package com.briup.pts.config.auth;

import com.briup.pts.domain.bean.Account;

/**
 * @author 25095
 * @description
 * @data 2024/11/26-09:50
 */
public class UserDetails {
    private static final ThreadLocal<Account> THREAD_LOCAL
            =new ThreadLocal<>();

    public static void setCurrentUser(Account account){
        THREAD_LOCAL.set(account);
    }
    //根据当前执行任务的线程，获取到其对应用户的对象
    public static Account currentUser(){
        return THREAD_LOCAL.get();
    }
    //从当前对象获取用户名
    public static String username(){
        return currentUser().getUsername();
    }

    //清空ThreadLocal内部中属于当前线程的数据
    public static  void clear(){
        THREAD_LOCAL.remove();
    }
}
